package com.harunasan.carrental.api.serve.utils;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 订单编号生成工具类
 * @author liangyi
 * @since 2022/3/10 14:13
 */
@Component
public class OrderNumberUtil {
    private final static String DATE_FORMAT = "yyyyMMdd";
    public String generateOrderNumber(){
        String prefix= getDate();
        return prefix+ IdWorker.getIdStr();
    }

    private static String getDate(){
        DateTimeFormatter dateFormatter =   DateTimeFormatter.ofPattern(DATE_FORMAT);
        return LocalDate.now().format(dateFormatter);
    }
}
